import sys

print("Python版本:", sys.version)
print("\n开始导入TensorFlow...")

try:
    import tensorflow as tf
    print("✓ TensorFlow导入成功")
    
    print(f"TensorFlow版本: {tf.__version__}")
    
    # 检查设备
    print("\n=== 设备信息 ===")
    gpus = tf.config.list_physical_devices('GPU')
    cpus = tf.config.list_physical_devices('CPU')
    print(f"GPU设备: {gpus}")
    print(f"CPU设备: {cpus}")
    
    # 简单的TensorFlow操作
    print("\n=== 基本操作测试 ===")
    hello = tf.constant('Hello, TensorFlow!')
    print("字符串常量:", hello.numpy().decode())
    
    a = tf.constant(5)
    b = tf.constant(3)
    c = a + b
    print(f"数学运算: {a.numpy()} + {b.numpy()} = {c.numpy()}")
    
    print("\n✓ 所有测试通过！")
    
except ImportError as e:
    print("✗ 导入TensorFlow失败:", e)
except Exception as e:
    print("✗ 发生错误:", e)

input("按Enter键退出...")  # 防止窗口立即关闭